#pragma once

#include <Windows.h>
#include <iostream>
#include <string>

using namespace std;

#include "serialport.h"

struct packet
{
	CHAR startOfHeader;
	BYTE packetNum;
	BYTE packetNumCompl;
	CHAR fileData[128];
	BYTE checkSum1;
	BYTE checkSum2;
};

class Nadajnik
{
public:
	Nadajnik(void);
	Nadajnik(string _port);

	~Nadajnik(void);

	BOOL sendFile(string fileName);

private:
	enum 
	{
		soh = 0x01,
		eot = 0x04,
		ack = 0x06,
		nak = 0x15,
		can = 0x18,
		c = 0x43
	};


	WORD CRC();
	BYTE checkSum();

	bool makePacket(HFILE _hFile);

	serialport* port;
	packet dataToSend;
	
	HFILE hFile;
	OFSTRUCT openFileStruct;

	BOOL useCRC;
	CHAR initSign;
	BYTE packetNumber;

	WORD crc;
	BYTE checksum;

};

